package coletaDados;

import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;

public class Coleta {

	private Busca estrategiaBusca;
	private Twitter twitter = new TwitterFactory().getInstance();
	private DBStatus base;
	private boolean failed = true;

	public Coleta(int qntUser, int qntPag, String dir) {
		base = new DBStatus(twitter, dir);
		this.estrategiaBusca = new Largura(twitter, qntUser, qntPag, base);
	}

	public Busca getEstrategiaBusca() {
		return estrategiaBusca;
	}

	public void setEstrategiaBusca(Busca estrategiaBusca) {
		this.estrategiaBusca = estrategiaBusca;
	}

	public boolean getFailed(){
		return this.failed;
	}
	
	public DBStatus getBase() {
		return base;
	}

	public void setBase(DBStatus base) {
		this.base = base;
	}

	public void processPorAmigos(String nameUser) {
		try {
			estrategiaBusca
					.executarBuscaPorAmigos((twitter.showUser(nameUser)));
			failed = false;
		} catch (TwitterException e) {
			System.err.println("HTTP error: " + e.getStatusCode());
			e.printStackTrace();
			System.out.println("Retentando...");
			failed = true;
		}
	}

	public void processPorReferencias(String nameUser) {
		try {
			estrategiaBusca.executarBuscaPorReferenciados(twitter
					.showUser(nameUser));
			failed = false;
		} catch (TwitterException e) {
			System.err.println("HTTP error: " + e.getStatusCode());
			System.out.println("Retentando...");
			failed = true;
		}
	}

	public static void main(String[] args) throws Exception {
		Coleta coleta = new Coleta(100, 4, "captura_Amigos_Fonema");
		while(coleta.getFailed())
			coleta.processPorAmigos("tuntzen");
		//coleta.getBase().setDiretorio("captura_Referencias");
		//coleta.processPorReferencias("saviorobertto");
	}
}
